import { FormSchema } from '@/components/Form';
import { BasicColumn } from '@/components/Table';
import { DescItem } from '@/components/Description';
import { h } from 'vue';
import { Tinymce } from '@/components/Tinymce';
import { DicSortEnum } from '@/enums';

import { listOpMaterialGroupApi } from '@/api/operations/materialgroup.api';

/** 表格数据 */
export const columns: BasicColumn[] = [
  {
    title: '分类ID',
    dataIndex: 'groupId',
    width: 220,
  },
  {
    title: '材料名称',
    dataIndex: 'title',
    width: 220,
  },
  {
    title: '资料编号',
    dataIndex: 'materialNumber',
    width: 220,
  },
  {
    title: '关键字',
    dataIndex: 'keywords',
    width: 220,
  },
  {
    title: '简介',
    dataIndex: 'introduction',
    width: 220,
  },
  {
    title: '附件',
    dataIndex: 'attachment',
    width: 220,
  },
  {
    title: '材料内容',
    dataIndex: 'content',
    width: 220,
  },
];

/** 查询数据 */
export const searchFormSchema: FormSchema[] = [
  {
    label: '材料名称',
    field: 'title',
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    label: '资料编号',
    field: 'materialNumber',
    component: 'Input',
    colProps: { span: 6 },
  },
];

/** 表单数据 */
export const formSchema: FormSchema[] = [
  {
    label: '主键ID',
    field: 'id',
    component: 'Input',
    show: false,
    colProps: { span: 12 },
  },
  {
    label: '资料分类',
    field: 'groupId',
    component: 'ApiTreeSelect',
    componentProps: {
      showSearch: true,
      api: listOpMaterialGroupApi,
      treeNodeFilterProp: 'groupName',
      labelField: 'groupName',
      valueField: 'id',
      getPopupContainer: () => document.body,
    },
    required: true,
    colProps: { span: 24 },
  },
  {
    label: '材料名称',
    field: 'title',
    component: 'Input',
    required: true,
    colProps: { span: 12 },
  },
  {
    label: '资料编号',
    field: 'materialNumber',
    component: 'Input',
    colProps: { span: 12 },
  },
  {
    label: '关键字',
    field: 'keywords',
    component: 'Input',
    colProps: { span: 12 },
  },
  {
    label: '简介',
    field: 'introduction',
    component: 'InputTextArea',
    colProps: { span: 24 },
  },
  {
    label: '附件',
    field: 'attachmentArr',
    component: 'Upload',
    colProps: { span: 24 },
    componentProps:{
        maxNumber:10,
        maxSize: 5,
    },
  },
  {
    label: '材料内容',
    field: 'content',
    component: 'Input',
    render: ({ model, field }) => {
      return h(Tinymce, {
        value: model[field],
        onChange: (value: string) => {
          model[field] = value;
        },
      })
    },
    colProps: { span: 24 },
  },
];

/** 详情数据 */
export const detailSchema: DescItem[] = [
  {
    label: '分类ID',
    field: 'groupId',
    span: 12,
  },
  {
    label: '材料名称',
    field: 'title',
    span: 12,
  },
  {
    label: '资料编号',
    field: 'materialNumber',
    span: 12,
  },
  {
    label: '关键字',
    field: 'keywords',
    span: 12,
  },
  {
    label: '简介',
    field: 'introduction',
    span: 12,
  },
  {
    label: '附件',
    field: 'attachment',
    span: 12,
  },
  {
    label: '材料内容',
    field: 'content',
    span: 12,
  },
];
